package com.goldsprite.horipush.screens;

import com.badlogic.gdx.*;
import com.badlogic.gdx.graphics.*;
import com.badlogic.gdx.graphics.g2d.*;
import com.badlogic.gdx.graphics.glutils.*;
import com.badlogic.gdx.scenes.scene2d.*;
import com.badlogic.gdx.scenes.scene2d.ui.*;
import com.badlogic.gdx.scenes.scene2d.utils.*;
import com.badlogic.gdx.utils.*;
import com.badlogic.gdx.utils.viewport.*;
import com.goldsprite.gameframeworks.assets.*;
import com.goldsprite.gameframeworks.screens.*;

public class StartScreen extends GScreen {
	private SpriteBatch batch;
	private ShapeRenderer shapeRenderer;
	private Texture logo, background;
	private Color backgroundColor = Color.valueOf("#000000FF"), clearColor = Color.valueOf("#333333FF");

	float worldWidth = 960, worldHeight = 540;
	private FitViewport worldViewport;
	private OrthographicCamera cam;

	private Stage stage;

	private TextButton startBtn;

	@Override
	public Viewport getViewport(){
		return worldViewport;
	}


	@Override
	public void create() {
		shapeRenderer = new ShapeRenderer();

		batch = new SpriteBatch();
		logo = new Texture("libgdx.png");

		worldViewport = new FitViewport(worldWidth, worldHeight);
		
		stage = new Stage(worldViewport);
		getImp().addProcessor(stage);
		
		Skin skin = GlobalAssets.getInstance().editorSkin;
		int k2;
		startBtn = new TextButton("进入游戏", skin);
		startBtn.setSize(220, 60);
		startBtn.setPosition(getViewSize().x/2f, getViewSize().y/2f - startBtn.getHeight()/2f - 100, Align.center);
		startBtn.addListener(new ClickListener() {
			@Override
			public void clicked(InputEvent event, float x, float y) {
				getScreenManager().setCurScreen(GameScreen.class, true);
			}
		});
		stage.addActor(startBtn);
	}

	@Override
	public void render(float delta) {
		ScreenUtils.clear(clearColor);
		float viewWidth = Gdx.graphics.getWidth();
		float viewHeight = Gdx.graphics.getHeight();
		float viewCenterX = viewWidth / 2f;
		float viewCenterY = viewHeight / 2f;
		float worldCenterX = worldWidth / 2f;
		float worldCenterY = worldHeight / 2f;

		worldViewport.apply(true);

		shapeRenderer.setProjectionMatrix(worldViewport.getCamera().combined);
		shapeRenderer.begin(ShapeRenderer.ShapeType.Filled);
		shapeRenderer.setColor(backgroundColor);
		shapeRenderer.rect(0, 0, worldWidth, worldHeight);
		shapeRenderer.end();

		batch.setProjectionMatrix(worldViewport.getCamera().combined);
		batch.begin();
		{
			float logoWidth = logo.getWidth();
			float logoHeight = logo.getHeight();
			batch.draw(logo, worldCenterX - logoWidth / 2, worldCenterY - logoHeight / 2, logoWidth, logoHeight);
		}
		batch.end();
		
		stage.act(delta);
		stage.draw();
	}

	@Override
	public void resize(int width, int height) {
		worldViewport.update(width, height, true);
	}
}

